﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FactoryMethod
{
    public class Operation
    {
        double _numberA; 
        double _numberB;

        public double NumberA
        {
            get { return _numberA; }
            set { _numberA = value; }
        }

        public double NumberB
        {
            get { return _numberB; }
            set { _numberB = value; }
        }


        public virtual double getResult()
        {
            return 0;
        }
    }

    public class OperationAdd : Operation
    {
        public override double getResult()
        {
            return NumberA + NumberB;
        }
    }

    public class OperationSub : Operation
    {
        public override double getResult()
        {
            return NumberA - NumberB;
        }
    }

    public class OperationMul : Operation
    {
        public override double getResult()
        {
            return NumberA * NumberB;
        }
    }

    public class OperationDiv : Operation
    {
        public override double getResult()
        {
            if (NumberB == 0)
                throw new Exception("除数不能为0");
            return NumberA / NumberB;
        }
    }
}
